package org.dromara.system.service.impl;

import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.utils.BeanCopyUtils;
import org.dromara.system.mapper.SysPostMapper;
import org.dromara.system.pojo.bo.SysPostBO;
import org.dromara.system.pojo.entity.SysPostDO;
import org.dromara.system.pojo.qo.SysPostQO;
import org.dromara.system.pojo.vo.SysPostVO;
import org.dromara.system.service.SysPostService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 岗位信息表 服务层实现。
 *
 * @author mkj
 * @since 2024-07-21
 */
@RequiredArgsConstructor
@Service
public class SysPostServiceImpl implements SysPostService {

    private final SysPostMapper sysPostMapper;

    @Override
    public boolean add(SysPostBO sysPostBO) {
        SysPostDO sysPostDO = BeanCopyUtils.copy(sysPostBO, SysPostDO.class);
        return sysPostMapper.insert(sysPostDO) > 0;
    }

    @Override
    public boolean remove(Long id) {
        return sysPostMapper.deleteById(id) > 0;
    }

    @Override
    public boolean update(SysPostBO sysPostBO) {
        SysPostDO sysPostDO = BeanCopyUtils.copy(sysPostBO, SysPostDO.class);
        return sysPostMapper.update(sysPostDO) > 0;
    }

    @Override
    public List<SysPostVO> list(SysPostQO sysPostQO) {
        SysPostDO sysPostDO = BeanCopyUtils.copy(sysPostQO, SysPostDO.class);
        QueryWrapper queryWrapper = QueryWrapper.create(sysPostDO);
        return sysPostMapper.selectListByQueryAs(queryWrapper, SysPostVO.class);
    }

    @Override
    public SysPostVO getInfo(Long id) {
        SysPostDO sysPostDO = sysPostMapper.selectOneById(id);
        if (sysPostDO == null) {
            return null;
        }
        return BeanCopyUtils.copy(sysPostDO, SysPostVO.class);
    }

    @Override
    public Page<SysPostVO> page(SysPostQO page) {
        return sysPostMapper.paginateAs(page.getPageNumber(), page.getPageSize(), QueryWrapper.create(page), SysPostVO.class);
    }

}

